﻿@model System.Web.Mvc.ViewPage<dynamic>
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>花样年主数据平台</title>
    <script src="/Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="/Scripts/JScriptCommon.js" type="text/javascript"></script>
    <script src="/Res/MyJs.js" type="text/javascript"></script>
    <script src="/Scripts/FormCheck.js" type="text/javascript"></script>
    <link href="/Res/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="/Res/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="/CSS/style.css" rel="stylesheet" type="text/css" />
    <link href="/CSS/indexstyle.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var dbName;
        var dbDisplayName;
        $(function () {
            tabCloseEven();
            $('ul li a').click(function () {
                var tabTitle = $(this).text();
                var url = $(this).attr("rel"); //获取地址
                var id = $(this).attr("id"); //获取id
                var icon = $(this).attr("icon"); //获取图标
                if (icon == "") {
                    icon = "icon-save";
                }
                addTab(tabTitle, url, icon, true, id);
            });
            $('#loginOut').click(function () {
                if (confirm('您确定要退出本次登录吗?')) {
                    location.href = '/Account/LogOff?time=' + (new Date()).getTime();
                }
            });

            //登陆信息
            $.post("/SysLog/GetLogInfo?time=" + (new Date()).getTime(), function (res) {
                $("#loginTime").html(res);
            });

            var weburl = window.location.href.replace("Home/Index", "") + "Webservice/Wanda_MDP.asmx";
            $("#webUrl").html("<a href='" + weburl + "' target='_blank'>" + weburl + "</a>");
            $('#myTree').tree({
                url: '/SysMenu/GetTree',
                onClick: function (node) {
                    if (node.attributes) {
                        var url = node.attributes["url"];
                        if (url != "" && url.indexOf("/") > -1 && url.indexOf("DBStatus=2") == -1) {
                            addTab(node.rootText + "-" + node.text, url, "", true, node.id);
                        }
                    }
                    $(this).tree('toggle', node.target);
                },
                onBeforeLoad: function (node, param) {
                    if (node) {
                        param.parentid = node.id;
                    }
                }, onContextMenu: function (e, node) {
                    if (node.iconCls && node.iconCls.indexOf("icon-db") > -1) {
                        e.preventDefault();
                        $(this).tree('select', node.target);
                        dbName = node.value;
                        dbDisplayName = node.text;
                        $("#mm2-tabupdate").html("<div>禁用</div>");
                        $("#mm2-4").html("<div>断开</div>");
                        $("#mmjob").html("<div>停止任务</div>");
                        $("#mm2-tabupdate").show();
                        $(".editDB").show();
                        if (node.id == "2") {//禁用
                            $("#mm2-tabupdate").html("<div>启用</div>");
                        } else if (node.id == "3") {//断开 
                            $("#mm2-4").html("<div>连接</div>");
                        } 
                        if (node.job == "0") {//停用
                            $("#mmjob").html("<div>启用任务</div>");
                        }
                        if (node.id == "-1") {//没有启禁用权限
                            $("#mm2-tabupdate").hide();
                            $(".editDB").hide();
                        }
                        $('#mm2').menu('show', {
                            left: e.pageX,
                            top: e.pageY
                        });
                    }
                }
            });
            $('#mm2-1').click(function () {
                $('#mm2').menu('hide');
                if (confirm("您将进行删除实例的操作，确认要删除实例吗？")) {
                    $.post("/Home/DropDataBase", { dbName: dbName }, function (result) {
                        alert(result);
                        $('#myTree').tree("reload");
                    });
                }
            });
            $('#mm2-tabupdate').click(function () {
                $('#mm2').menu('hide');
                var mmtext = $("#mm2-tabupdate div").html();
                if (confirm("您将进行" + mmtext + "实例的操作，确认要" + mmtext + "实例吗？")) {
                    $.post("/Home/StopDataBase", { status: mmtext, dbName: dbName }, function (result) {
                        alert(result);
                        $('#myTree').tree("reload");
                    });
                }
            });
            $('#mm2-4').click(function () {
                $('#mm2').menu('hide');
                var mmtext = $("#mm2-4 div").html();
                if (confirm("您将进行" + mmtext + "实例的操作，确认要" + mmtext + "实例吗？")) {
                    $.post("/Home/DisConnectDB", { status: mmtext, dbName: dbName }, function (result) {
                        alert(result);
                        $('#myTree').tree("reload");
                    });
                }
            });
            $('#mmjob').click(function () {
                $('#mm2').menu('hide');
                var mmtext = $("#mmjob div").html();
                if (confirm("您将进行" + mmtext + "的操作，确认要" + mmtext + "吗？")) {
                    $.post("/Home/DBJob", { status: mmtext, dbName: dbName }, function (result) {
                        alert(result);
                        $('#myTree').tree("reload");
                    });
                }
            });
            $('#mm2-2').click(function () {
                $('#mm2').menu('hide');
                showModalMany('Contact', '/Home/GetDBInfo/?mm=3&dbName=' + dbName + '&DisplayName=' + dbDisplayName, '700', '200');
            });  
            $('#mm2-3-1').click(function () {
                $('#mm2').menu('hide');
                showModalMany('Contact', '/Home/GetDBInfo/?mm=4&dbName=' + dbName + '&DisplayName=' + dbDisplayName, '700', '200');
            });
            $('#mm2-3-4').click(function () {
                $('#mm2').menu('hide');
                showModalMany('Contact', '/Home/GetDBInfo/?mm=5&dbName=' + dbName + '&DisplayName=' + dbDisplayName, '700', '200');
            });
            $('#mm2-5').click(function () {
                $('#mm2').menu('hide');
                showModalMany('Contact', '/Home/GetDBInfo/?mm=6&dbName=' + dbName + '&DisplayName=' + dbDisplayName, '500', '150');
            });
        });
        function TreeReload() {
            $('#myTree').tree("reload");
        }
        function addTab(title, url, icon, closable, id) { 
            if (!$('#hometabs').tabs('exists', title)) {
                $('#hometabs').tabs('add', {
                    title: title,
                    content: '<iframe id="' + id + '" scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:99%;overflow-y: auto; "></iframe>',
                    closable: closable
                });
            } else {
                $('#hometabs').tabs('select', title);
            }
            /*双击关闭TAB选项卡*/
            $(".tabs-inner").dblclick(function () {
                var title = $(this).children(".tabs-closable").text();
                $('#hometabs').tabs('close', title);
            })
            //tabClose();
        }
        function tabClose() {
            /*双击关闭TAB选项卡*/
            $(".tabs-inner").dblclick(function () {
                var subtitle = $(this).children(".tabs-closable").text();
                $('#hometabs').tabs('close', subtitle);
            })
            /*为选项卡绑定右键*/
            $(".tabs-inner").bind('contextmenu', function (e) {
                $('#mm').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });

                var subtitle = $(this).children(".tabs-closable").text();

                $('#mm').data("currtab", subtitle);
                $('#hometabs').tabs('select', subtitle);
                return false;
            });
        }
        //绑定右键菜单事件
        function tabCloseEven() {
            //退出
            $("#mm-exit").click(function () {
                $('#mm').menu('hide');
            });
        }
        function ChangePassword() {
            if (!$('#hometabs').tabs("exists", "修改密码")) {
                $('#hometabs').tabs('add', {
                    title: '修改密码',
                    content: $("#divChangePwd").html(),
                    closable: true
                });
            }
        }

        function btnChangePwd() {
            var oldPwd = $.trim($("#txtOldOwd").val());
            var pwd1 = $.trim($("#txtPwd1").val());
            var pwd2 = $.trim($("#txtPwd2").val());

            if (oldPwd == "") {
                alert("请输入原密码！");
                return;
            }
            if (pwd1 == "") {
                alert("请输入新密码！");
                return;
            }
            if (pwd2 == "") {
                alert("请输入确认密码！");
                return;
            }
            if (!checkPwdNum(pwd1)) {
                alert("新密码格式不正确，密码长度至少8位，必须包含数字、字母、特殊字符。");
                return false;
            }
            if (pwd1 != pwd2) {
                alert("两次输入的密码不一致，请重新输入！");
                $("#txtPwd1").val("");
                $("#txtPwd2").val("");
                return;
            } else {
                $.post("/Home/ChangePassword", { oldPwd: oldPwd, pwd: pwd1 }, function (result) {
                    if (result == 1) {
                        alert("密码修改成功,请重新登录！");
                        window.location.href = "/Account/LogOn";
                    } else if (result == 3) {
                        alert("原密码输入不正确！");
                    } else if (result == 0) {
                        alert("修改失败，请重新登录后重试！");
                    }
                    else {
                        alert(result);
                    }
                });
            }
        } 
    </script>
</head>
<body class="easyui-layout">
    <noscript>
        <div style="position: absolute; z-index: 100000; height: 2046px; top: 0px; left: 0px;
            width: 100%; background: white; text-align: center;">
            <img src="../images/noscript.gif" alt='抱歉，请开启脚本支持！' />
        </div>
    </noscript>
    <div region="north" split="true" border="false" style="overflow: hidden; height: 66px;
        line-height: 20px; color: #fff; font-family: 微软雅黑,黑体">
        <div class="top">
            <div class="logo_box">
            </div>
            <div id="mainctrl">
                <div style="padding-right: 5px; text-align: right; color: #ffffff; font-family: 微软雅黑;
                    float: right">
                    <table>
                        <tr>
                            <td>
                                <span style="font-size: 13px;">您好：@(Request.Cookies["MDM_EName"] == null ? "" : HttpUtility.UrlDecode(Request.Cookies["MDM_EName"].Value))</span>
                                ,欢迎您的光临！<br />
                                <a href="#" class="easyui-linkbutton" style="font-size: 12px; color: #ffffff;" onclick="return ChangePassword()"
                                    data-options="plain:true">修改密码</a> <a href="#" class="easyui-linkbutton" style="font-size: 12px;
                                        color: #ffffff;" id="loginOut" data-options="plain:true">安全退出</a>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div region="west" hide="true" split="true" title="导航菜单" style="width: 200px;" id="west">
        <div id="nav" class="easyui-accordion" fit="true" border="false" style="height: auto;
            overflow-y: scroll;">
            <!--  导航内容 -->
            <ul style="margin-top: 6px;" id="myTree">
            </ul>
        </div>
    </div>
    <div id="mainPanle" region="center" style="background: #eee; overflow-y: hidden;">
        <div id="hometabs" class="easyui-tabs" fit="true" border="false">
            <div title="我的工作台" class="myArea">
                <div style="font-size: 16px; font-weight: bold;">
                    欢迎使用花样年地产主数据平台.</div>
                <br />
                <div id="loginTime">
                    &nbsp;
                </div> 
            </div>
        </div>
    </div>
    <div id="mm" class="easyui-menu" style="width: 150px;">
        <div id="mm-tabupdate">
            刷新</div>
        <div class="menu-sep">
        </div>
        <div id="mm-tabclose">
            关闭</div>
    </div>
    <div id="mm2" class="easyui-menu" style="width: 110px;">
        <div id="mm2-tabupdate" class="menuMargin">
            &nbsp;
        </div>
        <div id="mm2-4" class="menuMargin">
            &nbsp;
        </div>
        <div id="mmjob" class="menuMargin">
            &nbsp;
        </div>
        <div class="menu-sep">
        </div>
        <div id="mm2-2">
            属性页</div>
        <div id="mm2-3">
            计划任务
            <div style="width: 110px;">
                <div id="mm2-3-1">
                    收缩数据库</div>
                <div id="mm2-3-4">
                    重新生成索引</div>
            </div>
        </div>
        <div id="mm2-5" class="editDB">
            重命名</div>
        <div class="menu-sep">
        </div>
        <div id="mm2-1" class="editDB">
            删除</div>
    </div>
    <div id="divChangePwd" style="display: none;">
        <div style="margin: 5px 0px 0px 5px;">
            <div class="easyui-panel" title="修改密码" style="width: 600px; height: 200px;">
                <br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="red">*</span>原密码：<input id="txtOldOwd" type="password" style="width: 200px;" /><br />
                <br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="red">*</span>新密码：<input id="txtPwd1" type="password" style="width: 200px;" /> 
                密码长度至少8位，必须包含数字、字母、特殊字符。<br />
                <br />
                &nbsp; <span class="red">*</span>确认密码：<input id="txtPwd2" type="password" style="width: 200px;" /><br />
                <br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" class="button" value="确认" onclick="btnChangePwd();" />&nbsp;
                <input type="button" class="button" value="取消" onclick="javascript:$('#hometabs').tabs('close',
    '修改密码');" />
            </div>
        </div>
    </div>
</body>
</html>
